package reflect;


import java.lang.reflect.Method;
import java.util.Scanner;

public class ReflectDemo1 {
    public static void main(String[] args) throws ClassNotFoundException {

        //1.通过.class获取类对象
        /*Class class1 = String.class;//获取String的Class对象
        Class class2 = ArrayList.class;//获取ArrayList的Class对象
        Class class3 = int.class;//获取int的Class对象


        //2.通过指定类的完全限定名称获取一个类的类对象
        Class class4 = Class.forName("java.lang.String");
        Class class5 = Class.forName("java.util.ArrayList");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个类名");
        String className = scanner.next();
        Class class6 = Class.forName(className);*/
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个类名");
        String className = scanner.next();
        Class cls = Class.forName(className);

        System.out.println("获取类的完全限定名"+cls.getName());
        System.out.println("获取类名"+cls.getSimpleName());


        Package pack = cls.getPackage();
        System.out.println("获取包名"+pack.getName());


        Method[] methods = cls.getMethods();
        System.out.println("获取所有方法"+methods.length);

        for(Method method : methods){
            System.out.println(method.getName());
        }

     }
}
